﻿using System;
using HK.Core.Common.Protocol;
using HK.Core.Common.Protocol.Data;

namespace HK.Core.Common.Data
{
    /// <summary>
    /// 数据基类
    /// </summary>
    [Serializable]
    public class DataBase : IDataBase
    {
        /// <summary>
        /// 类名.
        /// </summary>
        private string _className;
        public string ClassName {
            get { 
                if(false == string.IsNullOrEmpty(_className)) {
                    return _className;
                }
                _className = GetType().Name;
                return _className;
            }
        }
        
        /// <summary>
        /// 有效标志位
        /// </summary>
        public virtual bool Valid => true;
        
#region Dirty

        /// <summary>
        /// 标脏字段
        /// <para>* 且在对象存活期间有效</para>
        /// <para>* true:有变更; false:无变更;</para>
        /// </summary>
        public bool Dirty { get; protected set; } = false;

        /// <summary>
        /// 重置标脏标志位
        /// </summary>
        public void ResetDirty() => Dirty = false;

#endregion

        /// <summary>
        /// 清空.
        /// </summary>
        public virtual void Clear()
        {
            Dirty = false;
        }

    }
}
